home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / winpos.c < prev    next >
C/C++ Source or Header  |  1999-02-04  |  3KB  |  121 lines

  1. /* $Id: winpos.c,v 3.0 1998/01/31 21:07:51 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.0
  6.  * Copyright (C) 1995-1998  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: winpos.c,v $
  26.  * Revision 3.0  1998/01/31 21:07:51  brianp
  27.  * initial rev
  28.  *
  29.  */
  30.  
  31.  
  32. /*
  33.  * GL_MESA_window_pos extension
  34.  *
  35.  * This extension offers a set of functions named glWindowPos*MESA() which
  36.  * directly set the current raster position to the given window coordinate.
  37.  * glWindowPos*MESA() are similar to glRasterPos*() but bypass the
  38.  * modelview, projection and viewport transformations.
  39.  *
  40.  * These functions should be very handy in conjunction with glDrawPixels()
  41.  * and glCopyPixels().
  42.  *
  43.  * If your application uses glWindowPos*MESA() and may be compiled with
  44.  * a real OpenGL instead of Mesa you can simply copy the winpos.[ch] files
  45.  * into your source tree and compile them with the rest of your code
  46.  * since glWindowPos*MESA() can, and is, implemented in terms of standard
  47.  * OpenGL commands when not using Mesa.  In your source files which use
  48.  * glWindowPos*MESA() just #include "winpos.h".
  49.  */
  50.  
  51.  
  52.  
  53. #ifdef PC_HEADER
  54. #include "all.h"
  55. #else
  56. #include "GL/gl.h"
  57. #endif
  58.  
  59. #ifdef GL_MESA_window_pos
  60.  
  61.  
  62. #ifndef PC_HEADER
  63. #include "rastpos.h"
  64. #include "winpos.h"
  65. #endif
  66.  
  67.  
  68.  
  69. /*
  70.  * Mesa implementation of glWindowPos*MESA()
  71.  */
  72. void gl_WindowPos4fMESA( GLcontext *ctx,
  73.                          GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  74. {
  75.    gl_windowpos( ctx, x, y, z, w );
  76. }
  77.  
  78.  
  79. #else
  80.  
  81.  
  82. /*
  83.  * OpenGL implementation of glWindowPos*MESA()
  84.  */
  85. void glWindowPos4fMESA( GLfloat x, GLfloat y, GLfloat z, GLfloat w )
  86. {
  87.    GLfloat fx, fy;
  88.  
  89.    /* Push current matrix mode and viewport attributes */
  90.    glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
  91.  
  92.    /* Setup projection parameters */
  93.    glMatrixMode( GL_PROJECTION );
  94.    glPushMatrix();
  95.    glLoadIdentity();
  96.    glMatrixMode( GL_MODELVIEW );
  97.    glPushMatrix();
  98.    glLoadIdentity();
  99.  
  100.    glDepthRange( z, z );
  101.    glViewport( (int) x - 1, (int) y - 1, 2, 2 );
  102.  
  103.    /* set the raster (window) position */
  104.    fx = x - (int) x;
  105.    fy = y - (int) y;
  106.    glRasterPos4f( fx, fy, 0.0, w );
  107.  
  108.    /* restore matrices, viewport and matrix mode */
  109.    glPopMatrix();
  110.    glMatrixMode( GL_PROJECTION );
  111.    glPopMatrix();
  112.  
  113.    glPopAttrib();
  114. }
  115.  
  116.  
  117. #endif
  118.  
  119.  
  120.  
  121.